home *** CD-ROM | disk | FTP | other *** search
- Path: mail2news.demon.co.uk!genesis.demon.co.uk
- From: Lawrence Kirby <fred@genesis.demon.co.uk>
- Newsgroups: comp.lang.c
- Subject: Re: Logical exclusive-or
- Date: Tue, 06 Feb 96 14:58:28 GMT
- Organization: none
- Message-ID: <823618708snz@genesis.demon.co.uk>
- References: <4f6lrq$bcr@lastactionhero.rs.itd.umich.edu> <4f7688$4te@beach.and.nl>
- Reply-To: fred@genesis.demon.co.uk
- X-NNTP-Posting-Host: genesis.demon.co.uk
- X-Newsreader: Demon Internet Simple News v1.27
- X-Mail2News-Path: genesis.demon.co.uk
-
- In article <4f7688$4te@beach.and.nl> jos@and.nl "Jos A. Horsmeier" writes:
-
- >In article <4f6lrq$bcr@lastactionhero.rs.itd.umich.edu>, davidm@umich.edu
- >wrote:
- >
- >|Is there a good reason why C doesn't have a logical exclusive-or
- >|operator? A look at the precedence hierarchy suggests an obvious
- >|symbol and precedence for such an operator:
- >|
- >| bitwise and &
- >| bitwise exclusive or ^
- >| bitwise inclusive or |
- >| logical and &&
- >| logical or ||
- >|
- >|The logical exclusive or would be represented by ^^ and have
- >|precedence higher than || but lower than && . If C requires machines
- >|to be able to implement bitwise XOR, then it would seem reasonable to
- >|require the logical operator also.
-
- It is the nature of C to tend towards minimalism which is one of the
- reasons it is a good and successful language (I'm not saying everything in
- the language can be justified on this basis). You seem to be asking 'why
- isn't it in the language' whereas the correct question is 'why should it
- be in the language'? In that particular case it adds little or nothing
- to the language hence is correctly left out. Another way of looking at it
- is that ANSI (mostly) standardised 'existing practice'. Since none of the
- existing C implementations at the time thought ^^ useful the ANSI committee
- didn't either.
-
- >Note that although the logical 'and' and 'or' operators do not
- >evaluate their right operand if their left operand is false or
- >true resepectively, the 'logical exclusive or' operator must
- >evaluate both operands no matter what the value of the left hand
- >operand is. So the sole purpose of a '^^' operator would be a lexical
- >shorthand for:
- >
- > a ^^ b == (!(a) != !(b))
-
- They do define sequence points between their operands which can be
- simulated for '^^' with:
-
- #define LXOR(a,b) ((a) ? !(b) : !!(b))
-
- >That wouldn't be much of added functionality, would it?
-
- Right. It may be useful once in a blue moon but that's not a good enough
- reason to add something to a language given that the same functionality
- can be simulated easily enough with existing language constructs.
-
- --
- -----------------------------------------
- Lawrence Kirby | fred@genesis.demon.co.uk
- Wilts, England | 70734.126@compuserve.com
- -----------------------------------------
-